package com.sky.websocket;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.DateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @Author: WangHongKun
 * @Date: 2022/9/22 16:58
 * @Email: 2028911483@qq.com
 * @Phone: 18683977706
 */

@Component
@Slf4j
public class WebSocketTask {


    @Autowired
    private  WebSocketServer webSocketServer;


    @Scheduled(cron = "0/5 * * * * ? ")
    public void sendMessage(){
        webSocketServer.sendToAllClient("这是来自服务端的消息：" + DateTimeFormatter.ofPattern(
                "HH:mm:ss"
        ).format(LocalDateTime.now()));
    }
}
